<?php
session_start();
?>
<meta name="viewport" charset="utf-8" content="width=device-width, initial-scale=1.0">
<?php
$admin = $_REQUEST['adminno'];
$password = $_REQUEST['password'];
$level = $_REQUEST['level'];
if ($admin == "" || $password == "") {
    echo '<script type="text/javascript">alert("用户名或密码不能为空");location="index.php";</script>';
    exit;
}
$mysqli = mysqli_connect("localhost", "root", "123456", "library");
mysqli_query($mysqli,"SET NAMES 'utf8'");
if (mysqli_connect_errno()) {
    die("Failed to connect to MySQL: (" . mysqli_connect_errno() . ") " . mysqli_connect_error());
}
$demand = "select password,level,adminname from Admin where adminno = '$admin'";
$res = mysqli_query($mysqli, $demand);
$power = mysqli_fetch_row($res);
$_SESSION["adminno"]=$admin;
$_SESSION["adminname"]=$power[2];
$_SESSION["password"]=$password;
if ($power[0] == $password) {
    if ($power[1] == 'reader') {
        header('location:index_reader.php');
    } else if ($power[1] == 'normal') {
        header('location:index_normal.php');
    }else if ($power[1] == 'super') {
        header('location:index_super.php');
    } else {
        echo '<script type="text/javascript">alert("未知错误，请联系管理员");location="index.html";</script>';
        exit;
    }
} else {
    echo '<script type="text/javascript">alert("用户名或密码错误，请重新登陆");location="index.html";</script>';
}
mysqli_free_result($res);
mysqli_close($mysqli);
